package com.time.timespace.controller;

import com.time.timespace.commons.dto.ResponseEntity;
import com.time.timespace.domain.entity.Category;
import com.time.timespace.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "分类管理")
@Slf4j
@RequestMapping("/category")
public class CategoryController {

    private final CategoryService categoryService;

    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @Operation(description = "查询所有分类信息")
    @GetMapping("/select-all")
    public ResponseEntity<List<Category>> selectAll(Long userId) {
        return ResponseEntity.success(categoryService.selectAll(userId));
    }

    @Operation(description = "保存分类信息")
    @PostMapping("/save-category")
    public ResponseEntity<Category> saveCategory(@RequestBody Category category) {
        return ResponseEntity.success(categoryService.saveCategory(category));
    }

    @Operation(description = "删除分类信息")
    @GetMapping("/delete-category/{id}")
    public ResponseEntity<Void> deleteCategory(@PathVariable("id") Long id) {
        categoryService.deleteCategory(id);
        return ResponseEntity.success();
    }
}